package cn.jingyuan.swan.cloud.core;


import cn.jingyuan.bee.exception.ErrorCode;

import java.util.Objects;

public abstract class ExCodeUtils {

    public static boolean isSuccess(ErrorCode exCode) {
        nonNull(exCode);
        String code = ExCode.SUCCESS.code;
        return code.equals(exCode.getCode());
    }

    public static boolean isSuccess(String errCode) {
        nonNull(errCode);
        String code = ExCode.SUCCESS.code;
        return code.equals(errCode);
    }

    public static boolean isError(ErrorCode exCode) {
        return !isSuccess(exCode);
    }

    public static boolean isError(String errCode) {
        return !isSuccess(errCode);
    }

    public static boolean matchFailure(ErrorCode exCode) {
        nonNull(exCode);
        String code = ExCode.FAILURE.code;
        return code.equals(exCode.getCode());
    }

    public static boolean matchFailure(String errCode) {
        nonNull(errCode);
        String code = ExCode.FAILURE.code;
        return code.equals(errCode);
    }

    public static void nonNull(ErrorCode exCode) {
        Objects.requireNonNull(exCode, "'exCode' must be not null");
    }

    public static void nonNull(String errCode) {
        Objects.requireNonNull(errCode, "'errCode' must be not null");
    }

}
